/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.bean.BusinessBillBean;
import com.minierp.bean.BusinessBillItemBean;
import com.minierp.model.BusinessBill;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class BusiOnlineValidator implements Validator {
	public boolean supports(Class clazz) {
		return BusinessBillBean.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		BusinessBillBean bean = (BusinessBillBean) obj;
		BusinessBill form = bean.getBusinessBill();
		boolean hasError = false;
		if (!hasError) {
			try {
				SimpleDateFormat hasItems = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				form.setDeliverDate(hasItems.parse(bean.getDeliverDateStr()
						+ " " + bean.getDeliverDateHour() + ":"
						+ bean.getDeliverDateMinute() + ":00"));
			} catch (Exception arg8) {
				hasError = true;
				errors.rejectValue("deliverDateStr", "",
						"『交货日期』填写错误，请按以下格式输入：2008-01-01");
			}
		}

		if (!hasError) {
			Date arg9 = new Date();
			if (form.getDeliverDate().before(arg9)) {
				hasError = true;
				errors.rejectValue("deliverDateStr", "", "『交货日期』不能在当前时间之前");
			}
		}

		if (!hasError && form.getMark().length() > 200) {
			hasError = true;
			errors.rejectValue("businessBill.mark", "", "『备注』不能超过200个字符");
		}

		if (!hasError) {
			boolean arg10 = false;

			for (int i = 0; i < bean.getItems().size(); ++i) {
				BusinessBillItemBean cb = (BusinessBillItemBean) bean
						.getItems().get(i);
				if (!cb.getStatus().equals("DELETE")) {
					arg10 = true;
					break;
				}
			}

			if (!arg10) {
				hasError = true;
				errors.rejectValue("items", "", "明细不能为空");
			}
		}

	}
}